package receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class SDCardReceiver extends BroadcastReceiver {
    public static String MEDIA_MOUNTED="android.intent.action.MEDIA_MOUNTED";
    public static String MEDIA_REMOVED="android.intent.action.MEDIA_REMOVED";
    public static String MEDIA_UNMOUNTED="android.intent.action.MEDIA_UNMOUNTED";
    public SDCardReceiver() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        String action=intent.getAction();
      if(action.equals(MEDIA_MOUNTED)){
          Toast.makeText(context,"SD卡可用",Toast.LENGTH_SHORT).show();
       }else if(action.equals(MEDIA_REMOVED)){
          Toast.makeText(context,"SD卡拔出",Toast.LENGTH_SHORT).show();
      }else if(action.equals(MEDIA_UNMOUNTED)){
          Toast.makeText(context,"SD卡不可用",Toast.LENGTH_SHORT).show();
      }
    }
}
